package User;
import Manager.Product;

import javax.naming.Name;
import java.util.ArrayList;
import java.util.List;

public class Order {
    public List<Product> products = new ArrayList<>();
    public boolean isPaid = false;
    void addProduct(Product product) {
        products.add(product);
    }
    public double getTotal() {
        double total = 0;
        for (Product product : products) {
            total += product.price;
        }
        return total;
    }
    public void pay(){
        if (!isPaid){
            isPaid = true;
            System.out.println("支付成功，总金额: ¥" + getTotal());
        } else {
            System.out.println("订单已支付");
        }
    }
    public void refund(){
        if (isPaid){
            System.out.println("退款成功，金额: ¥" + getTotal());
            isPaid = false;
            products.clear();
        }
        else{
            System.out.println("订单未支付，无法退款");
        }
    }
    public  void wszb(Product product){
        if (!isPaid){
            product.stock+=product.num;
        }
    }
}

